﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace template_dll
{
    public partial class ChildForm : Form
    {
        public ChildForm()
        {
            InitializeComponent();
        }

        private const string namechcol = "Флаг";
        private SqlConnection conn;
        private DataTable dt_rep;
        private delegate void Deleg();
        private Deleg del;    
        
        public static bool DisplayForm(System.Windows.Forms.Form theMDIParent)
        {
            ChildForm f = new ChildForm();
            f.MdiParent = theMDIParent;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
            return true;
        }

        private string GetServ(string filename)
        {
            string str = "";
            using (StreamReader streamReader = new StreamReader(filename))
            {
                while (!streamReader.EndOfStream)
                {
                    str += streamReader.ReadLine();
                }
            }
            return str;
        }

        private void ChildForm_Load(object sender, EventArgs e)
        {
            UpdateRTB();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UpdateRTB();
        }

        private void UpdateRTB()
        {
            conn = new SqlConnection(@"Server=" + GetServ("serv.txt") + ";Database=SecurityFA;Integrated Security=True");
            dt_rep = (new SqlStorProc()).SqlProcExecWithQueryOneTable(conn, "pas_InformSel", 60, null);
            richTextBox1.Clear();
            foreach (DataRow row in dt_rep.Rows)
            {
                string date = "Обновление от " + Convert.ToDateTime(row[1]).ToString("dd.MM.yyyy");
                string title = row[2].ToString();
                string comm = row[3].ToString();
                string r1 = "/*************************************************/\n";

                richTextBox1.AppendText(r1);
                richTextBox1.AppendText("\n");
                richTextBox1.AppendText(date);
                richTextBox1.Select(richTextBox1.Text.Length - date.Length, date.Length);
                richTextBox1.SelectionFont = new Font(richTextBox1.Font.FontFamily, (this.Font.Size * 2), FontStyle.Bold);
                //richTextBox1.AppendText(r2);
                richTextBox1.AppendText("\n");
                richTextBox1.AppendText(title);
                richTextBox1.Select(richTextBox1.Text.Length - title.Length, title.Length);
                richTextBox1.SelectionFont = new Font(richTextBox1.Font.FontFamily, (this.Font.Size * (float)2.5), FontStyle.Bold);
                //richTextBox1.AppendText(r2);
                richTextBox1.AppendText("\n\n");
                richTextBox1.AppendText(comm);
                richTextBox1.AppendText("\n");
                //richTextBox1.AppendText(r1);
                richTextBox1.AppendText("\n");
                richTextBox1.SelectionAlignment = HorizontalAlignment.Center;

            }
        }


    }
}
